from typing import List, Dict

class ReplyGenerator:
    """根据交互响应字段动态生成回复参数的类"""
    
    def __init__(self, interactive_responses: List[Dict[str, str]]):
        """
        初始化回复生成器

        Args:
            interactive_responses: 包含提示词和响应内容的字典列表
        """
        self.responses = []
        
        for item in interactive_responses:
            self.responses.append({
                'prompt': item.get('prompt'),
                'response': item.get('response'),
                'reply_times': item.get('reply_times', 1),  # 默认响应次数为1
                'expect': item.get('expect')
            })
        
        # self.reply_index = 0  # 用于记录当前应回复的响应

    def generate_reply(self, output: str) -> str:
        """
        根据命令输出生成适当的回复
        
        Args:
            output: 命令的标准输出
            
        Returns:
            str: 自动生成的回复内容
        """
        # 查询当前提示词的响应
        reply_index = 0
        while reply_index < len(self.responses):
            prompt = self.responses[reply_index]['prompt']
            if prompt in output:
                response = self.responses[reply_index]['response']
                reply_times = self.responses[reply_index]['reply_times']
                if reply_times > 0:
                    self.responses[reply_index]['reply_times'] -= 1
                    return response
                else:
                    reply_index += 1
                    continue
            else:
                reply_index += 1
                continue
        return ""
